/**
 * 系统用户表& #40;成为智能& #41;管理初始化
 */
var UserCw = {
    id: "UserCwTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    deptid:0
};

/**
 * 初始化表格的列
 */
UserCw.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '用户编号', field: 'suId', visible: false, align: 'center', valign: 'middle'},
            {title: '角色编号', field: 'srId', visible: false, align: 'center', valign: 'middle'},
            {title: '主岗ID', field: 'spId', visible: false, align: 'center', valign: 'middle'},
            {title: '兼职岗位ID', field: 'supId', visible: false, align: 'center', valign: 'middle'},
            {title: '机构编号', field: 'soId', visible: false, align: 'center', valign: 'middle'},
            {title: '登录名', field: 'suLoginName', visible: true, align: 'center', valign: 'middle'},
            {title: '登录密码', field: 'suLoginPwd', visible: false, align: 'center', valign: 'middle'},
            {title: '盐', field: 'suSalt', visible: true, align: 'center', valign: 'middle'},
            {title: '手机号码', field: 'suPhone', visible: true, align: 'center', valign: 'middle'},
            {title: '邮箱号', field: 'suEmail', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: false, align: 'center', valign: 'middle'},
            {title: '创建人', field: 'creareUser', visible: true, align: 'center', valign: 'middle'},
            {title: '用户状态', field: 'suState', visible: true, align: 'center', valign: 'middle'},
            {title: '显示顺序', field: 'suSort', visible: false, align: 'center', valign: 'middle'},
            {title: '用户头像ID', field: 'suImg', visible: false, align: 'center', valign: 'middle'},
            {title: '证件类型', field: 'suIdcardType', visible: true, align: 'center', valign: 'middle'},
            {title: '证件号码', field: 'suIdcardNum', visible: true, align: 'center', valign: 'middle'},
            {title: '姓名', field: 'suiName', visible: false, align: 'center', valign: 'middle'},
            {title: '拼音', field: 'suiPy', visible: false, align: 'center', valign: 'middle'},
            {title: '全拼', field: 'suiPyAll', visible: false, align: 'center', valign: 'middle'},
            {title: '拼音首字母', field: 'suiPyFirst', visible: false, align: 'center', valign: 'middle'},
            {title: '性别', field: 'suiSex', visible: true, align: 'center', valign: 'middle'},
            {title: '民族', field: 'suiNation', visible: true, align: 'center', valign: 'middle'},
            {title: '出生年月', field: 'suiBirthday', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'suiRemark', visible: false, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
UserCw.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        UserCw.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加系统用户表& #40;成为智能& #41;
 */
UserCw.openAddUserCw = function () {
    var index = layer.open({
        type: 2,
        title: '添加系统用户表& #40;成为智能& #41;',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/userCw/userCw_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看系统用户表& #40;成为智能& #41;详情
 */
UserCw.openUserCwDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '系统用户表(成为智能)详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/userCw/userCw_update/' + UserCw.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除系统用户表& #40;成为智能& #41;
 */
UserCw.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/userCw/delete", function (data) {
            Feng.success("删除成功!");
            UserCw.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("userCwId",this.seItem.id);
        ajax.start();
    }
};
/**
 * 冻结用户账户
 * @param userId
 */
UserCw.freezeAccount = function () {
    if (this.check()) {
        var userId = this.seItem.id;
        var ajax = new $ax(Feng.ctxPath + "/mgr/freeze", function (data) {
            Feng.success("冻结成功!");
            MgrUser.table.refresh();
        }, function (data) {
            Feng.error("冻结失败!" + data.responseJSON.message + "!");
        });
        ajax.set("userId", userId);
        ajax.start();
    }
};

/**
 * 解除冻结用户账户
 * @param userId
 */
UserCw.unfreeze = function () {
    if (this.check()) {
        var userId = this.seItem.id;
        var ajax = new $ax(Feng.ctxPath + "/mgr/unfreeze", function (data) {
            Feng.success("解除冻结成功!");
            MgrUser.table.refresh();
        }, function (data) {
            Feng.error("解除冻结失败!");
        });
        ajax.set("userId", userId);
        ajax.start();
    }
};

/**
 * 重置密码
 */
UserCw.resetPwd = function () {
    if (this.check()) {
        var userId = this.seItem.id;
        parent.layer.confirm('是否重置密码为111111？', {
            btn: ['确定', '取消'],
            shade: false //不显示遮罩
        }, function () {
            var ajax = new $ax(Feng.ctxPath + "/mgr/reset", function (data) {
                Feng.success("重置密码成功!");
            }, function (data) {
                Feng.error("重置密码失败!");
            });
            ajax.set("userId", userId);
            ajax.start();
        });
    }
};
/**
 * 查询系统用户表& #40;成为智能& #41;列表
 */
UserCw.search = function () {
    var queryData = {};
    queryData['soId'] = UserCw.soId;
    queryData['name'] = $("#name").val();
    UserCw.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = UserCw.initColumn();
    var table = new BSTable(UserCw.id, "/userCw/list", defaultColunms);
    table.setPaginationType("client");
    UserCw.table = table.init();
    var ztree = new $ZTree("deptTree", "/dept/tree");
    ztree.bindOnClick(UserCw.onClickDept);
    ztree.init();
});
